package mmi.gui.widget;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * 
 * @author louis
 *
 */
public class StringAsker extends JDialog implements ActionListener {
	private static final long serialVersionUID = -8819917282411437342L;
	private String returnValue = null;

	private JTextField tf = null;

	private JButton okButton = null;

	private JButton cancelButton = null;
	public StringAsker(JFrame frame, boolean modal) {
		super(frame, modal);
		initialise();
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(okButton == e.getSource()) {
			returnValue = tf.getText();
			setVisible(false);
		}
		else if(cancelButton == e.getSource()) {
			returnValue = null;
			setVisible(false);
		}
	}
	public String getValue()
	{
		return returnValue;
	}

	private void initialise()
	{
		setSize(800, 500);

		JPanel panel = new JPanel();
		getContentPane().add(panel);
		panel.add(new JLabel("Enter string"));

		panel.setLayout(new BorderLayout());

		tf = new JTextField();
		panel.add(tf, BorderLayout.NORTH);

		okButton = new JButton("OK");
		okButton.addActionListener(this);
		panel.add(okButton, BorderLayout.EAST);

		cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(this);
		panel.add(cancelButton, BorderLayout.WEST);

		pack();

		setLocationRelativeTo(null);
		setVisible(true);
	}

}
